package com.itheima.ai.Tool;

import com.itheima.ai.entity.TbShop;
import com.itheima.ai.entity.TbShopType;
import com.itheima.ai.entity.TbVoucher;
import com.itheima.ai.entity.TbVoucherOrder;
import com.itheima.ai.service.ITbShopService;
import com.itheima.ai.service.ITbShopTypeService;
import com.itheima.ai.service.ITbVoucherOrderService;
import com.itheima.ai.service.ITbVoucherService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.UUID;

@RequiredArgsConstructor
@Component
public class CourseTools {

    private final ITbShopService tbShopService;
    private final ITbShopTypeService tbShopTypeService;
    private final ITbVoucherService tbVoucherService;
    private final ITbVoucherOrderService tbVoucherOrderService;

    @Tool(description = "获取所有店铺类型")
    public List<TbShopType> getShopTypes() {
        return tbShopTypeService.list();
    }

    @Tool(description = "获取所有店铺")
    public List<TbShop> getShops(Long shopTypeId) {
        return tbShopService.list();
    }

    @Tool(description = "获取所有优惠券")
    public List<TbVoucher> getVouchers() {
        return tbVoucherService.list();
    }

    @Tool(description = "下单优惠券，返回优惠券编号")
    public Long  orderVoucher(Long voucherId) {
        // 使用UUID随机生成一个id
        Long id = UUID.randomUUID().getMostSignificantBits();
        Long userId = 1l;
        TbVoucherOrder tbVoucherOrder = new TbVoucherOrder();
        tbVoucherOrder.setId(id);
        tbVoucherOrder.setUserId(userId);
        tbVoucherOrder.setVoucherId(voucherId);
        tbVoucherOrderService.save(tbVoucherOrder);
        return id;
    }

}
